<template>
  <div class="page openMessageMarketing">
    <div class="scroll-view">
      <customHeader middleTitle="提交开通资料" />
      <div class="page-body">
        <div class="form-title">负责人信息</div>
        <ul class="form-style">
          <li>
            <span>姓名</span>
            <div>
              <inputClear
                v-model="userName"
                placeholder="请输入负责人姓名"
                warpClass="alignRight"
                :maxlength="10"
                @blur="validate('userName')"
              ></inputClear>
            </div>
          </li>
          <li>
            <span>手机号</span>
            <div>
              <inputClear
                type="number"
                v-model="mobile"
                placeholder="请输入负责人手机号"
                warpClass="alignRight"
                :maxlength="11"
                @blur="validate('mobile')"
              ></inputClear>
            </div>
          </li>
        </ul>
        <div class="form-title">短信基础设置</div>
        <ul class="form-style">
          <li>
            <span>签名</span>
            <div>
              <inputClear
                v-model="sign"
                placeholder="请输入签名"
                warpClass="alignRight"
                :maxlength="10"
                @blur="validate('sign')"
              ></inputClear>
            </div>
          </li>
        </ul>
        <div class="form-tip">
          仅支持汉字，最多输入10个字符；
          <br />签名将出现在短信内容中，一般使用“商户/品牌”简称
        </div>
        <div class="btn-wrap">
          <div class="btn" @click="submit">提交</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import customHeader from "../../components/header/header";
import inputClear from "../../components/inputClear/inputClear";
import { Toast } from "mint-ui";
import jsBridge from "../../tools/jsBridge.js";
export default {
  name: "openMessageMarketing",
  data() {
    return {
      userName: "",
      mobile: "",
      sign: "",
    };
  },
  methods: {
    validate(fieldName, isSubmit) {
      const han = /^[\u4e00-\u9fa5]+$/;
      if (fieldName === "userName" || isSubmit === true) {
        if (!this.userName) {
          Toast("请输入负责人姓名");
          return false;
        }
        if (!han.test(this.userName)) {
          Toast("姓名只可填写汉字");
          return false;
        }
      }
      if (fieldName === "mobile" || isSubmit === true) {
        if (!this.mobile) {
          Toast("请输入负责人手机号");
          return false;
        }
        if (!CommonUtil.checkMobile(this.mobile)) {
          Toast("请输入正确的手机号码");
          return false;
        }
      }
      if (fieldName === "sign" || isSubmit === true) {
        if (!this.sign) {
          Toast("请输入签名");
          return false;
        }
        if (!han.test(this.sign)) {
          Toast("签名仅支持汉字，最多输入10个字符");
          return false;
        }
      }
      return true;
    },
    //获取老板信息
    getBossInfo(){
      this.ajax({
        url: "/newapp/smsmarketing/getBossInfo.do",
        type: "get",
        controlLoading: false
      })
        .then(res => {
          if (res.success&&res.resultObject) {
             this.mobile= res.resultObject.mobile;
          }   
        })
        .catch(function (err) {

        });
    },
    submit() {
      if (!this.validate(null, true)) {
        return;
      }
      const param = { userName: this.userName, mobile: this.mobile, sign: this.sign };
      this.ajax({
        url: "/newapp/smsmarketing/addAccount.do",
        type: "POST",
        data: param,
        controlLoading: true
      })
        .then(res => {
          if (res.success) {
            sessionStorage.setItem("mallTabIndex", 0);
            this.$router.push({ path: "/mallList", query: { close: true } });
          } else {
            Toast(res.msg);
          }
        })
        .catch(function (err) {

        });
    },
  },
  computed: {

  },
  created() {
    this.getBossInfo();
  },

  components: {
    customHeader,
    inputClear
  }
};
</script>
<style lang="scss" scoped>
@import "messageMarketing";
</style>
<style lang="scss">
.alignRight {
  text-align: right !important;
}
</style>
